/*
 * @lc app=leetcode.cn id=507 lang=rust
 *
 * [507] 完美数
 */

// @lc code=start
impl Solution {
    pub fn check_perfect_number(num: i32) -> bool {
        if (num < 6) {return false;}
        //6是第一个完美数
        let mut sum = 1;
        // use std::num::sqrt;
        let limit = (num as f64).sqrt() as i32 + 1;

        for i in 2..limit {
            if (num % i == 0){
                sum += i;
                sum += num / i;
            }
        }

        return sum == num;
    }
}
// @lc code=end

